package edu.mbb.cloud.nacos;

import edu.mbb.cloud.nacos.listen.ConfigService;
import edu.mbb.cloud.nacos.listen.NacosConfigService;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Properties;

@ConfigurationProperties(prefix = "spring.mbb")
public class MbbConfigProPerties {


    private String serverAddr;
    /**
     * encode for nacos config content.
     */
    private String encode;
    /**
     * nacos config group, group is config data meta info.
     */
    private String group = "DEFAULT_GROUP";
    /**
     * the suffix of nacos config dataId, also the file extension of config content.
     */
    private String fileExtension = "properties";
    /**
     * namespace, separation configuration of different environments.
     */
    private String namespace;


    private String prefix;

    private String name;


    private ConfigService configService;

    public ConfigService getConfigService() {
        return configService;
    }

    public void setConfigService(ConfigService configService) {
        this.configService = configService;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getServerAddr() {
        return serverAddr;
    }

    public void setServerAddr(String serverAddr) {
        this.serverAddr = serverAddr;
    }

    public String getEncode() {
        return encode;
    }

    public void setEncode(String encode) {
        this.encode = encode;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getFileExtension() {
        return fileExtension;
    }

    public void setFileExtension(String fileExtension) {
        this.fileExtension = fileExtension;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public ConfigService configServiceInstance( Properties properties) {
        //nacos 原生用的反射
        if(configService!=null){
            return configService;
        }
        configService = new NacosConfigService(properties);
        return configService;
    }
}
